#include	<sys/select.h>
#include	<sys/time.h>
#include	<sys/types.h>
#include	<sys/socket.h>
#include	<arpa/inet.h>
#include	<unistd.h>
#include	<stdio.h>
#include	"server.h"

void		init_client(t_fdc *fdc, int s)
{
  int		cs;
  struct sockaddr_in	client_sin;
  unsigned int		client_sin_len;

  client_sin_len = sizeof(client_sin);
  cs = xaccept(s, (struct sockaddr *)&client_sin, &client_sin_len);
  fdc->fd_type[cs] = FD_CLIENT;
  fdc->fct_read[cs] = client_read;
  fdc->fct_write[cs] = NULL;
}

void		init_server(t_fdc *fdc)
{
  int			s;
  struct sockaddr_in	sin;

  s = xsocket(PF_INET, SOCK_STREAM, 0);
  sin.sin_family = AF_INET;
  sin.sin_port = htons(fdc->port);
  sin.sin_addr.s_addr = INADDR_ANY;
  xbind(s, (struct sockaddr*)&sin, sizeof(sin));
  xlisten(s, 42);
  fdc->fd_type[s] = FD_SERVER;
  fdc->fct_read[s] = server_read;
  fdc->fct_write[s] = NULL;
}
